tree grammar vslTree;

options {
    tokenVocab=vsl;
    ASTLabelType=CommonTree;
}

//@header {}

//@members {}

expression returns [Expratt exp]
		@init{exp = null;}
		:	^(PLUS exp1=expression  exp2=expression)
			{Type ty = TypeSystem.CheckBinOp(exp1.type, exp2.type);
				  Tokatt temp = SymbDistrib.newTemp();
				  Code cod = Code.genBinOp(Inst3a.TAC_ADD, exp1, exp2, temp);
				  exp = new Expratt(ty, cod, temp);}
		|	^(MOINS exp1=expression exp2=expression)
			{Type ty = TypeSystem.CheckBinOp(exp1.type, exp2.type);
				  Tokatt temp = SymbDistrib.newTemp();
				  Code cod = Code.genBinOp(Inst3a.TAC_SUB, exp1, exp2, temp);
				  exp = new Expratt(ty, cod, temp);}
		|	^(MUL exp1=expression  exp2=expression)
			{Type ty = TypeSystem.CheckBinOp(exp1.type, exp2.type);
				  Tokatt temp = SymbDistrib.newTemp();
				  Code cod = Code.genBinOp(Inst3a.TAC_MUL, exp1, exp2, temp);
				  exp = new Expratt(ty, cod, temp);}
		|	^(DIV exp1=expression  exp2=expression)
			{Type ty = TypeSystem.CheckBinOp(exp1.type, exp2.type);
				  Tokatt temp = SymbDistrib.newTemp();
				  Code cod = Code.genBinOp(Inst3a.TAC_DIV, exp1, exp2, temp);
				  exp = new Expratt(ty, cod, temp);}
		|	e = primaire {exp=e;}
		;

primaire  returns [Expratt exp]
		@init{exp = null;}
		:	i=INTEGER
			{int ival =Integer.parseInt(i.getText());
				 exp = new Expratt(TypeSystem.T_integer, new Code(), new Tokatt(ival));}
		;
